home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_11_06
/
1106082a
< prev
next >
Wrap
Text File
|
1993-04-06
|
1KB
|
45 lines
/*******************************************
*
* find_cutoff_point(..
*
* This function looks at a histogram
* and sets a cuttoff point at a given
* percentage of pixels.
* For example, if percent=0.6, you
* start at 0 in the histogram and count
* up until you've hit 60% of the pixels.
* Then you stop and return that pixel
* value.
*
********************************************/
find_cutoff_point(histogram, percent, cutoff)
unsigned long histogram[];
float percent;
short *cutoff;
{
float fd, fsum, sum_div;
int i, looking;
long lc, lr, num=0, sum=0;
sum = 0;
i = 0;
lr = (long)(ROWS);
lc = (long)(COLS);
num = lr*lc;
fd = (float)(num);
while(looking){
fsum = (float)(sum);
sum_div = fsum/fd;
if(sum_div >= percent)
looking = 0;
else
sum = sum + histogram[i++];
} /* ends while looking */
if(i >= 256) i = 255;
*cutoff = i;
printf("\nCutoff is %d sum=%ld", *cutoff, sum);
} /* ends find_cutoff_point */